package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.Praise;
import cn.wolfcode.trip.base.mapper.PraiseMapper;
import cn.wolfcode.trip.base.query.PraiseQueryObject;
import cn.wolfcode.trip.base.service.IPraiseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class PraiseServiceImpl implements IPraiseService {
    @Autowired
    private PraiseMapper praiseMapper;

    @Override
    public void saveOrUpdatePraise(Praise praise) {
        if (praise.getId()==null){
            praiseMapper.insert(praise);
        }else {
            praiseMapper.updateByPrimaryKey(praise);
        }
    }

    @Override
    public Praise get(Praise entity) {
        Praise p = praiseMapper.selectByPraise(entity);
        if (p!=null){
            return p;
        }else {
           throw new RuntimeException("还没点过赞");
        }
    }


    @Override
    public List<Praise> getUserIdLike(PraiseQueryObject qo) {

        return praiseMapper.selectAll(qo);
    }

    @Override
    public void update(PraiseQueryObject qo) {
        praiseMapper.updateState(qo);
    }


    @Override
    public Integer getPraiseNum(Long typeId, Integer type) {
        return praiseMapper.getPraiseNum(typeId,type);
    }

    @Override
    public void updatePraise(Praise entity) {
        praiseMapper.updatePraise(entity);
    }
}
